package com.cleaningcloud.cld.controller.mini;

import com.cleaningcloud.cld.domain.*;
import com.cleaningcloud.cld.domain.dto.*;
import com.cleaningcloud.cld.domain.vo.CldInvoiceVo;
import com.cleaningcloud.cld.domain.vo.CldRegularMeetingVo;
import com.cleaningcloud.cld.domain.vo.CldRegularPlanVo;
import com.cleaningcloud.cld.service.*;
import com.cleaningcloud.cld.service.mini.IMiniProjectService;
import com.cleaningcloud.common.core.web.controller.BaseController;
import com.cleaningcloud.common.core.web.domain.AjaxResult;
import com.cleaningcloud.common.core.web.page.TableDataInfo;
import io.swagger.v3.oas.annotations.Operation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.List;

/**
 * 项目管理 - 小程序接口
 */
@RestController
@RequestMapping("/mini/project")
public class MiniProjectController extends BaseController {

    @Autowired
    private IMiniProjectService miniProjectService;

    @Autowired
    private ICldProjectService cldProjectService;

    @Autowired
    private PublicCommonService publicCommonService;

    @Autowired
    private ICldProjectPostService cldProjectPostService;

    @Autowired
    private ICldInvoiceService cldInvoiceService;

    @Autowired
    private ICldProjectSetService projectSetService;

    @Autowired
    private ICldRegularPlanService regularPlanService;

    @Autowired
    private ICldRegularMeetingService regularMeetingService;


    @Operation(description = "获取项目列表")
    @GetMapping("/getProjectList")
    public AjaxResult getProjectList(CldProject cldProject) {
        return success(cldProjectService.getList(cldProject));
    }

    @Operation(description = "根据项目id获取项目小组及人员配置")
    @GetMapping("/getGroupStaff/{projectId}")
    public AjaxResult getGroupStaff(@PathVariable Long projectId, @RequestParam(name = "isMasterDuits", required = false) Long isMasterDuits) {
        return success(publicCommonService.selectGroupStaffByProjectId(projectId, isMasterDuits));
    }

    @Operation(description = "获取项目小组岗位")
    @GetMapping("/getGroupPost")
    public AjaxResult getGroupPost(CldProjectPostDto cldProjectPostDto) {
        cldProjectPostDto.getParams().put("notNullStaffId", "1");
        return success(cldProjectPostService.selectCldProjectPostList(cldProjectPostDto));
    }


    @Operation(description = "根据项目ID获取项目配置")
    @GetMapping("/getProjectSet/{projectId}")
    public AjaxResult getProjectSet(@PathVariable Long projectId) {
        return success(projectSetService.getCldProjectSetByProjectId(projectId));
    }


    @Operation(description = "查询工作计划列表")
    @GetMapping("/getWorkPlanList")
    public TableDataInfo getWorkPlanList(CldWorkplanDto cldWorkplanDto) {
        startPage();
        return getMiniDataTable(miniProjectService.getWorkPlanList(cldWorkplanDto));
    }

    /**
     * @Author Shaw
     * @Description 查询工作计划列表
     * @date: 2025-06-10 16:37
     * @param: //TODO
     */
    @Operation(description = "查询工作计划列表(待审核 未通过 已通过)")
    @GetMapping("/getWorkPlanListDate")
    public TableDataInfo getWorkPlanListDate(CldWorkplanDto cldWorkplanDto) {
        startPage();
        return getMiniDataTable(miniProjectService.getWorkPlanListDate(cldWorkplanDto));
    }

    /**
     * @Author Shaw
     * @Description 小程序(客户端)-查询工作计划详情
     * @date: 2025-06-10 16:36
     * @param: //TODO
     */
    @Operation(description = "小程序(客户端)-查询工作计划详情")
    @GetMapping("/getCustomerWorkPlanInfo/{workPlanId}")
    public AjaxResult getCustomerWorkPlanInfo(@PathVariable Long workPlanId,@RequestParam(name = "rowDate", required = false) String rowDate,
        @RequestParam(name = "postId", required = false) Long postId,@RequestParam(name = "staffId", required = false) Long staffId) {
        return success(miniProjectService.getCustomerWorkPlanInfo(workPlanId, rowDate, postId,staffId));
    }

    /**
     * @Author Shaw
     * @Description 查询工作计划详情
     * @date: 2025-06-10 16:36
     * @param: //TODO
     */
    @Operation(description = "查询工作计划明细")
    @GetMapping("/getWorkPlanInfo/{workPlanId}")
    public AjaxResult getWorkPlanInfo(@PathVariable Long workPlanId,@RequestParam(name = "rowDate", required = false) Date rowDate,
        @RequestParam(name = "postId", required = false) Long postId) {
        return success(miniProjectService.selectCldWorkplanByWorkplanId(workPlanId, rowDate, postId));
    }


    @Operation(description = "工作计划提交")
    @PutMapping("/submitWorkPlan")
    public AjaxResult submitWorkPlan(@RequestBody CldWorkplanDto cldWorkplanDto) {
        return toAjax(miniProjectService.submitWorkPlan(cldWorkplanDto));
    }

    /**
     * @Author Shaw
     * @Description 小程序(客户端) - 工作计划审核
     * @date: 2025-06-10 16:34
     * @param: //TODO
     */
    @Operation(description = "工作计划审核")
    @PutMapping("/auditWorkPlan")
    public AjaxResult auditWorkPlan(@RequestBody CldWorkplanDto cldWorkplanDto) {
        return toAjax(miniProjectService.auditWorkPlan(cldWorkplanDto));
    }

    /**
     * @Author Shaw
     * @Description 小程序(客户端) - 工作(日)计划批量审核
     * @date: 2025-06-10 16:34
     * @param: //TODO
     */
    @Operation(description = "工作(日)计划批量审核")
    @PutMapping("/batchAuditWorkPlan")
    public AjaxResult batchAuditWorkPlan(@RequestBody CldWorkplanDto cldWorkplanDto) {
        return toAjax(miniProjectService.batchAuditWorkPlan(cldWorkplanDto));
    }

    @Operation(description = "发票列表查看")
    @GetMapping("/getInvoiceList")
    public TableDataInfo getInvoiceList(CldInvoiceDto cldInvoice) {
        startPage();
        List<CldInvoiceVo> list = cldInvoiceService.selectCldInvoiceList(cldInvoice);
        return getMiniDataTable(list);
    }

    @Operation(description = "获取发票详情")
    @GetMapping("/getInvoiceInfo/{invoiceId}")
    public AjaxResult getInvoiceInfo(@PathVariable Long invoiceId) {
        return success(cldInvoiceService.selectCldInvoiceByInvoiceId(invoiceId));
    }

    @Operation(description = "发票确认签收")
    @PutMapping("/invoiceReceipt")
    public AjaxResult invoiceReceipt(@RequestBody CldInvoice cldInvoice) {
        return toAjax(cldInvoiceService.invoiceReceipt(cldInvoice));
    }

    // ---------------------------------------------  例会详情  ---------------------------------------------
    /**
     * @Author Shaw
     * @Description 小程序(客户端)-例会列表
     * @date: 2025-06-11 12:11
     * @param: //TODO
     */
    @Operation(description = "小程序(客户端)-例会列表")
    @GetMapping("/getRegularMeetingList")
    public TableDataInfo getRegularMeetingList(CldRegularMeetingDto cldRegularMeetingDto) {
        startPage();
        List<CldRegularMeetingVo> list = miniProjectService.getRegularMeetingList(cldRegularMeetingDto);
        return getMiniDataTable(list);
    }

    /**
     * @Author Shaw
     * @Description 小程序(客户端)-例会计划列表
     * @date: 2025-06-11 12:11
     * @param: //TODO
     */
    @Operation(description = "小程序(客户端)-例会计划列表")
    @GetMapping("/getRegularPlanList")
    public TableDataInfo getRegularPlanList(CldRegularPlanDto cldRegularPlanDto) {
        startPage();
        List<CldRegularPlanVo> list = miniProjectService.getRegularPlanList(cldRegularPlanDto);
        return getMiniDataTable(list);
    }

    @Operation(description = "创建例会")
    @PostMapping("/addRegularMeeting")
    public AjaxResult addRegularMeeting(@RequestBody CldRegularMeetingDto cldRegularMeeting) {
        return toAjax(regularMeetingService.insertCldRegularMeeting(cldRegularMeeting));
    }

    @Operation(description = "获取例会详情")
    @GetMapping("/getRegularMeeting/{regularMeetingId}")
    public AjaxResult getRegularMeeting(@PathVariable Long regularMeetingId) {
        return success(regularMeetingService.selectCldRegularMeetingByRegularMeetingId(regularMeetingId));
    }

    @Operation(description = "创建例会计划")
    @PostMapping("/addRegularPlan")
    public AjaxResult addRegularPlan(@RequestBody CldRegularPlanDto cldRegularPlanDto) {
        return toAjax(regularPlanService.insertCldRegularPlan(cldRegularPlanDto));
    }

    @Operation(description = "查询例会计划明细")
    @GetMapping("/getRegularPlanById")
    public AjaxResult getRegularPlanById(CldRegularPlanDto cldRegularPlanDto) {
        return success(miniProjectService.getRegularPlanById(cldRegularPlanDto));
    }

    @Operation(description = "查看例会计划员工")
    @GetMapping("/getRegularPlanStaff")
    public AjaxResult getRegularPlanStaff(CldRegularPlanDto cldRegularPlanDto) {
        return success(miniProjectService.getRegularPlanStaff(cldRegularPlanDto));
    }

    @Operation(description = "查看例会计划员工提交明细")
    @GetMapping("/getRegularPlanStaffSubmit")
    public AjaxResult getRegularPlanStaffSubmit(CldRegularSubmit cldRegularSubmit) {
        return success(miniProjectService.getRegularPlanStaffSubmit(cldRegularSubmit));
    }

    @Operation(description = "例会列表查看")
    @GetMapping("/regularMeetingList")
    public TableDataInfo regularMeetingList(CldRegularMeetingDto cldRegularMeetingDto) {
        startPage();
        List<CldRegularMeetingVo> list = regularMeetingService.selectCldRegularMeetingList(cldRegularMeetingDto);
        return getMiniDataTable(list);
    }

    @Operation(description = "例会计划列表查看")
    @GetMapping("/regularPlanList")
    public TableDataInfo regularPlanList(CldRegularPlanDto cldRegularPlanDto) {
        startPage();
        List<CldRegularPlanVo> list = miniProjectService.regularPlanList(cldRegularPlanDto);
        return getMiniDataTable(list);
    }

    @Operation(description = "提交例会计划")
    @PostMapping("/submitRegularPlan")
    public AjaxResult submitRegularPlan(@RequestBody CldRegularPlanDto cldRegularPlanDto) {
        return toAjax(regularPlanService.submitCldRegularSubmitPlan(cldRegularPlanDto));
    }


}
